#include <atomic>
#include <thread>
#include <cassert>

bool x = false; // x is now a plain nonatomic variable
std::atomic<bool> y;
std::atomic<int> z;

void write_x_then_y()
{
	x = true;
	std::atomic_thread_fence(std::memory_order_release);
	y.store(true,std::memory_order_relaxed);
}

void read_y_then_x()
{
	while(!y.load(std::memory_order_relaxed));
	std::atomic_thread_fence(std::memory_order_acquire);
	if(x)
		++z;
}

int main()
{
	x = false;
	y = false;
	z = 0;
	std::thread a(write_x_then_y);
	std::thread b(read_y_then_x);
	a.join();
	b.join();
	assert(z.load()!=0);
}

